//
//  UIImage+EPM.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/1.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "UIImage+EPM.h"

@implementation UIImage (EPM)
+ (UIImage*)getCurrentScreenSnap{
    UIWindow* window = [UIApplication sharedApplication].keyWindow;
    UIGraphicsBeginImageContext(window.bounds.size);
    [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (UIImage*)getScaleImageWithMaxWidth:(CGFloat)maxWidth
{
    if (self.size.width < maxWidth){
        return self;
    }
    CGFloat maxHeight = self.size.height* maxWidth/self.size.width;
    CGRect rect = CGRectMake(0, 0, maxWidth, maxHeight);
    UIGraphicsBeginImageContext(rect.size);
    [self drawInRect:rect];
    UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
@end
